<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('福利地区参数配置')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: bootstrap-editable-css"/>

</head>
<style>
    table {
        border: 2px solid #E7EAEC !important;
    }

    th {
        border-left: 2px solid #E7EAEC !important;
    }


    .fht-cell{width:120px!important;}





</style>

<body class="gray-bg">
<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="user-form">
                    <input type="hidden" id="ComPidorDepTid" name="ComPidorDepTid">
                    <div class="select-list">
                        <ul>
                            <li>
                                地区代码：<input type="text" name="code"/>
                            </li>
                            <li>
                                地区名称：<input type="text" name="title"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>

            <div class="col-sm-12 select-table table-striped" >
                <table id="bootstrap-table">

                </table>
            </div>


        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: bootstrap-table-editable-js"/>

<script th:inline="javascript">
    var prefix = ctx + "welfare/region/welfareRegionParameterConfig";
    var Rounds = [];
    $(function () {
        var panehHidden = false;
        if ($(this).width() < 1000) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 350});
        queryRound();
        queryData();
         //$(".fixed-table-header").remove();
        $('#bootstrap-table').bootstrapTable(); // init via javascript

        $(window).resize(function () {
            $('#bootstrap-table').bootstrapTable('resetView');
        });





    });

    function queryRound() {
        $.ajax({
            async: false,
            url: prefix + "/findWelfareRound",
            data: {},
            type: "post",
            dataType: "json",
            success: function (data) {
                for (var i = 0; i < data.length; i++) {
                    Rounds.push({value: data[i].id, text: data[i].title});
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.modal.alertWarning("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }


    function queryData() {
        console.log(Rounds);
        var columns = [];
        var id = {field: '序号', title: '序号'};
        var code = {field: '地区代码', title: '地区代码'};
        var title = {field: '地区名称', title: '地区名称'};
        columns.push(id, code, title);
        var other;
        $.ajax({
            async: false,
            url: prefix + "/getColumn",
            data: {},
            type: "post",
            dataType: "json",
            success: function (data) {
                for (var i = 0; i < data.length; i++) {
                    var arry = data[i].field.split('@@');
                    if (arry[1] == '进位方式id') {
                        other = {
                            field: data[i].field, title: data[i].title, editable: {
                                type: 'select',
                                title: '进位方式',
                                source: function () {
                                    return Rounds;
                                }
                            }
                        }
                    } else {
                        other = {
                            field: data[i].field, title: data[i].title, editable: true
                        }
                    }
                    columns.push(other);
                }
                var options = {
                    code: "序号",
                    uniqueId: "序号",
                    url: prefix + "/list",
                    updateUrl: prefix + "/edit/{id}",
                    removeUrl: prefix + "/remove/{id}",
                    height: $(window).height() - 120,
                    onEditableSave: onEditableSave,
                    pagination : false,
                    modalName: "基本信息",
                    columns: columns,
                };
                $.table.init(options);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.modal.alertWarning("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

    function onEditableSave(field, row, oldValue, $el) {
        var cityId = row.序号;
        var benefitTypeAndXl = field;
        var updVal = row[field];
        $.ajax({
            url: prefix + "/update",
            data: {"cityId": cityId, "benefitTypeAndXl": benefitTypeAndXl, "updVal": updVal},
            type: "post",
            dataType: "json",
            success: function (data) {
                $.table.refresh();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.modal.alertWarning("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }
</script>
</body>
</html>